<!-- File: /app/View/Posts/index.ctp -->

<h1>Blog posts</h1>
<div class="boton">
	<div class="boton_content">
		<p><?php echo $this->Html->link('Criar Post', array('action' => 'add')); ?></p>
	</div>
</div>
<table>
    <tr>
        <th>Id</th>
        <th>Title</th>
                <th>Actions</th>
        <th>Created</th>
    </tr>

<!-- Aqui é onde nós percorremos nossa matriz $posts, imprimindo
as informações dos posts -->
	
	<div id="post_background">
		<?php foreach ($posts as $post): ?>
			<div class="post">
				<p><?php echo $users[$post['Post']['user_id']]; ?>
				
				<?php echo $this->Html->link($post['Post']['title'], array('action' => 'view', $post['Post']['id']));?>
				</p>
				<p>
				
				<?php
				if ($isLoged){
					if(($post['Post']['user_id'] == $userId) or $isAdmin=="admin"){
							
							 echo $this->Html->link($this->Html->image('icons/ico/modify.ico',
                                                        array("alt" => __('Edit'), "title" => __('Edit'),"width" => __('15'))), 
                                                        array('action' => 'edit', $post['Post']['id']), 
                                                        array('escape' => false));
                                        
							
		
							 echo $this->Form->postLink($this->Html->image('icons/ico/delete.ico',
                                                array("alt" => __('Delete'), "title" => __('Delete'),"width" => __('15'))), 
                                                array('action' => 'delete', $post['Post']['id']),
                                                array('escape' => false),
						__('Você tem certeza?'));
								
					}
				}
				?>
						
						<?php echo $post['Post']['created']; ?>
					</p>
				
			</div>
		<?php endforeach; ?>
	</div>

</table>